﻿namespace OleDbDAL.Systems
{
    using DBUtility;
    using IDal.Systems;
    using Model.Systems;
    using System;
    using System.Data;
    using System.Text;

    public class PopedomTempApp : IPopedomTemp
    {
        private string dbname = "Systems";

        public void Add(PopedomTempEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into T_PopedomTemp(");
            builder.Append("PopTempFid,PopTempName,PopTempText,IsNextPop,IsPopUse,IsSuperPop");
            builder.Append(")");
            builder.Append(" values (");
            builder.Append("" + model.PopTempFid + ",");
            builder.Append("'" + model.PopTempName + "',");
            builder.Append("'" + model.PopTempText + "',");
            builder.Append("" + model.IsNextPop + ",");
            builder.Append("" + model.IsPopUse + ",");
            builder.Append("" + model.IsSuperPop + "");
            builder.Append(")");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public void Delete(int PopTempId)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from T_PopedomTemp ");
            builder.Append(" where PopTempId=" + PopTempId);
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public DataTable GetList(string strWhere)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from T_PopedomTemp ");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            builder.Append(" order by PopTempId ");
            return DbHelperOledb.Query(this.dbname, builder.ToString());
        }

        public int GetMaxId(string swhere)
        {
            return DbHelperOledb.GetMaxID(this.dbname, "PopTempId", "T_PopedomTemp", swhere);
        }

        public PopedomTempEnt GetModel(int PopTempId)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select PopTempId,PopTempFid,PopTempName,PopTempText,IsNextPop,IsPopUse,IsSuperPop from T_PopedomTemp ");
            builder.Append(" where PopTempId=" + PopTempId);
            PopedomTempEnt ent = new PopedomTempEnt();
            DataTable table = DbHelperOledb.Query(this.dbname, builder.ToString());
            ent.PopTempId = PopTempId;
            if (table.Rows.Count > 0)
            {
                if (table.Rows[0]["PopTempFid"].ToString() != "")
                {
                    ent.PopTempFid = int.Parse(table.Rows[0]["PopTempFid"].ToString());
                }
                ent.PopTempName = table.Rows[0]["PopTempName"].ToString();
                ent.PopTempText = table.Rows[0]["PopTempText"].ToString();
                if (table.Rows[0]["IsNextPop"].ToString() != "")
                {
                    ent.IsNextPop = int.Parse(table.Rows[0]["IsNextPop"].ToString());
                }
                if (table.Rows[0]["IsPopUse"].ToString() != "")
                {
                    ent.IsPopUse = int.Parse(table.Rows[0]["IsPopUse"].ToString());
                }
                if (table.Rows[0]["IsSuperPop"].ToString() != "")
                {
                    ent.IsSuperPop = int.Parse(table.Rows[0]["IsSuperPop"].ToString());
                }
                return ent;
            }
            return null;
        }

        public DataTable GetPageList(int PageSize, int PageIndex, string strWhere)
        {
            string orderString = "";
            int pageCount = 0;
            int recordCount = 0;
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from T_PopedomTemp ");
            return DbHelperOledb.ExecutePager(this.dbname, PageIndex, PageSize, "", builder.ToString(), strWhere, orderString, out pageCount, out recordCount, "PopTempId");
        }

        public void Update(PopedomTempEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update T_PopedomTemp set ");
            builder.Append("PopTempFid=" + model.PopTempFid + ",");
            builder.Append("PopTempName='" + model.PopTempName + "',");
            builder.Append("PopTempText='" + model.PopTempText + "',");
            builder.Append("IsNextPop=" + model.IsNextPop + ",");
            builder.Append("IsPopUse=" + model.IsPopUse + ",");
            builder.Append("IsSuperPop=" + model.IsSuperPop + "");
            builder.Append(" where PopTempId=" + model.PopTempId + "");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }
    }
}

